//
//  RansomDetailController.m
//  LuCaiZhu
//
//  Created by 邓龙 on 2019/4/22.
//

#import "RansomDetailController.h"
#import "HandleNetProduct+Transaction.h"
#import "RansomNewController.h"
#import "Header.h"
#import "CKPuslichTool.h"
#import "RansomOrderCell.h"

@interface RansomDetailController ()<UITableViewDelegate, UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *detailTable;
@property (nonatomic, strong) NSDictionary *detailDic;

@end

@implementation RansomDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"详细信息";
    _detailTable.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    
    [self getRansomDetailInfo];
}

//获取赎回详情信息
- (void)getRansomDetailInfo {
    [HandleNetProduct ransomDetailInfoRansomID:_redeemId isDq: _IsDq Success:^(NSDictionary * _Nonnull data) {
        _detailDic = data;
        [_detailTable reloadData];
    } Failure:^(NSString * _Nonnull errorInfo) {
        
    }];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 8;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    RansomOrderCell *cell = nil;
    if (indexPath.row == 1 || indexPath.row == 4 || indexPath.row == 7) {
        cell = [tableView dequeueReusableCellWithIdentifier:@"RansomOrderCell2"];
    }
    else {
        cell = [tableView dequeueReusableCellWithIdentifier:@"RansomOrderCell3"];
    }
    if (_detailDic) {
        [cell setRansomDetailAction:_detailDic index:indexPath.row];
    }
    return cell;
}

- (IBAction)clickDetailAction:(UIButton *)sender {
    RansomNewController *vc = (RansomNewController *)[CKPuslichTool getViewControllerFromStroyBoard:@"Transaction" viewID:@"RansomNewController"];
    vc.isDetail = YES;
    vc.redeemId = _detailDic[@"RedeemID"];
    if ([_detailDic[@"RedeemStatus"] isEqualToString:@"赎回成功"]) {
        vc.state = YES;
    }
    else {
        vc.state = NO;
    }
    [self.navigationController pushViewController:vc animated:YES];
}

@end
